package com.southminority.ethnic.service.redis.impl;

import com.southminority.ethnic.service.redis.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;
@Service
public class RedisServiceImpl implements RedisService {
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public Boolean redisSetValue(String key, String value, Long expireTime, TimeUnit unit) {

        return redisTemplate.opsForValue().setIfAbsent(key, value,expireTime,unit);
    }

    @Override
    public String redisGetValue(String key) {
        return (String) redisTemplate.opsForValue().get(key);
    }

    @Override
    public Long redisGetExpireTime(String key,TimeUnit unit) {
        return (Long) redisTemplate.getExpire(key, unit);
    }

    @Override
    public Boolean redisDelete(String key) {
        return redisTemplate.delete(key);
    }

    @Override
    public Boolean expire(String key, long timeout, TimeUnit unit) {
        return redisTemplate.expire(key, timeout, unit);
    }
}
